#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10, INF = 0x3f3f3f3f;
int a[maxn], b[maxn];
int g[maxn];
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int n; cin >> n;
    map<int, int> P;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i], P[b[i]] = i;

    memset(g, INF, sizeof(g));
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int p = P[a[i]];
        int k = lower_bound(g+1, g+1+n, p) - g;
        g[k] = p;
        ans = max(ans, k);
    }
    cout << ans;
    return 0;
}